package util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


public class DBUtils {
	private static final String className = "oracle.jdbc.OracleDriver";		//ojdbc6.jar->oracle.jdbc->OracleDriver.Class
	private static final String url = "jdbc:oracle:thin:@ITA-031-W7:1521/xe";//包装了oracle的�??议
	private static final String username = "jordan";
	private static final String psw = "123";
	public static Connection createConnection(){
	
		Connection con = null;
		try {
			Class.forName(className);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		try {
			con = DriverManager.getConnection(url, username, psw);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return con;
	}	
	public static void close(Connection conn,PreparedStatement pst,ResultSet rs){
		try {
			if (rs!=null) {
				rs.close();
			}
			if (pst!=null) {
				pst.close();
			}
			if (conn!=null) {
				conn.close();
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
	}
}
